package com.roc.web.action.agent;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;

public class AgentSubsidySearchCondition  extends BaseSearchCondition{

	/**
	 * file
	 * long:serialVersionUID:AgentSubsidySearchCondition.java
	 */
	
	private static final long serialVersionUID = 1L;
	
	private String merNo;  //商户号	
	private String merName;  //商户名
	private String certif; //法人名称
	private String certifNo;//法人身份证
	private String merBankAccount;//商户结算卡号
	private String deviceCd;//终端序列号
	private String busiLiceNo;//营业执照号码
	private String orgCode;
	private String agentId;
	private String roleType;//角色类型
	private String opId;

	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		//商户号
		 if(Constance.isNotEmpty(merNo)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("T.mcht_cd", merNo.trim(),"=", false));
		}
		 //商户名称
		 if(Constance.isNotEmpty(merName)){ //商户名称 （模糊）
				filedBeanList.add(new WhereHQLFieldBean("T.name_busi", merName.trim(), "like", false,"ALL"));
			}
		 //法人名称
		 if(Constance.isNotEmpty(certif)){ 
				filedBeanList.add(new WhereHQLFieldBean("T.CERTIF", certif.trim(),"=", false));
			}
		 //法人身份证
		 if(Constance.isNotEmpty(certifNo)){ 
				filedBeanList.add(new WhereHQLFieldBean("T.CERTIF_NO", certifNo.trim(),"=", false));
			}
		 //商户结算卡号
		 if(Constance.isNotEmpty(merBankAccount)){ 
				filedBeanList.add(new WhereHQLFieldBean("T.merchant_bank_account", merBankAccount.trim(),"=", false));
			}
		 //终端序列号
		 if(Constance.isNotEmpty(deviceCd)){ 
				filedBeanList.add(new WhereHQLFieldBean("T.device_cd", deviceCd.trim(),"=", false));
			}
		 //营业执照
		 if(Constance.isNotEmpty(busiLiceNo)){ 
				filedBeanList.add(new WhereHQLFieldBean("T.BUSI_LICE_NO", busiLiceNo.trim(),"=", false));
			}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		
		StringBuffer sb = new StringBuffer();
//		sb=sb.append(" select count(1)  from t_operators  t where 1=1  " );
		
		if (roleType.equals(Role.AGENT.getCode() )) {
			sb = sb.append(" select count(1) ")
					.append(" FROM T_OPERATORS_SUBSIDY_info t,TBL_MER_AGENT_RELATION TM ")
					.append(" where  T.MCHT_CD=TM.MERNO  ")
				    .append(" and T.STATUS='S' ")
					.append(" and TM.agentid=").append(agentId);
		}else{
			sb = sb.append(" select count(1) ")
					.append("  FROM T_OPERATORS_SUBSIDY_info t" )
					.append(" where  T.STATUS='S' ");
//					.append("T.STATUS='S' ");
		}
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {

		StringBuffer sb = new StringBuffer();

		if (roleType.equals(Role.AGENT.getCode())) {
			sb=sb.append(" SELECT t.mcht_cd,t.name_busi,t.certif,t.certif_no,t.busi_lice_no,t.agentname,op.real_name comName,pp.real_name oneName ,t.merchant_bank_account,t.merchant_bank_account_name,  " )
					.append("t.merchant_bank_name,t.device_cd,t.all_amt/100,t.all_count ,t.TRANS_MONTH,t.merinfo_status,t.terminal_status ")
					.append("  FROM T_OPERATORS_SUBSIDY_info t ")
					.append("  left join t_operators op on t.oneagentid=to_char(op.id) ")
					.append("  left join t_operators pp on t.COMPANYID=to_char(pp.id) ")
					.append("  left join TBL_MER_AGENT_RELATION TM on T.MCHT_CD=TM.MERNO ")
					.append(" where  1=1 ")
					.append(" and T.STATUS='S' ")
					.append(" and TM.agentid=").append(agentId);
		}else{
			sb=sb.append(" SELECT t.mcht_cd,t.name_busi,t.certif,t.certif_no,t.busi_lice_no,t.agentname,op.real_name comName,pp.real_name oneName ,t.merchant_bank_account,t.merchant_bank_account_name,  " )
					.append("t.merchant_bank_name,t.device_cd,t.all_amt/100,t.all_count ,t.TRANS_MONTH,t.merinfo_status,t.terminal_status ")
					.append("  FROM T_OPERATORS_SUBSIDY_info t ")
					.append("  left join t_operators op on t.oneagentid=to_char(op.id) ")
					.append("  left join t_operators pp on t.COMPANYID=to_char(pp.id) ")
					.append(" where  T.STATUS='S'");
//			        .append("T.STATUS='S' ");
		}
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return  " ";
	}

	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getCertif() {
		return certif;
	}

	public void setCertif(String certif) {
		this.certif = certif;
	}

	public String getCertifNo() {
		return certifNo;
	}

	public void setCertifNo(String certifNo) {
		this.certifNo = certifNo;
	}

	public String getMerBankAccount() {
		return merBankAccount;
	}

	public void setMerBankAccount(String merBankAccount) {
		this.merBankAccount = merBankAccount;
	}

	public String getDeviceCd() {
		return deviceCd;
	}

	public void setDeviceCd(String deviceCd) {
		this.deviceCd = deviceCd;
	}

	public String getBusiLiceNo() {
		return busiLiceNo;
	}

	public void setBusiLiceNo(String busiLiceNo) {
		this.busiLiceNo = busiLiceNo;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	public String getOpId() {
		return opId;
	}

	public void setOpId(String opId) {
		this.opId = opId;
	}


	
	
	
	
}
